package com.jdz.noise.controller;


import com.jdz.noise.dao.NoiseDao;
import com.jdz.noise.entities.FlyRow;
import com.jdz.noise.entities.GPS;
import com.jdz.noise.entities.NoiseRow;
import com.jdz.noise.entities.Point;
import com.jdz.noise.service.NoiseService;
import com.jdz.noise.tools.ControlUtil;
import com.jdz.noise.tools.Interpolation;
import com.jdz.noise.tools.Merge;
import com.jdz.noise.tools.SphereAlg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.jdz.noise.tools.ControlUtil.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;

@RestController
@Slf4j
public class NoiseController {
    @Resource
    private NoiseService noiseService;

    @Resource
    private NoiseDao noiseDao;

    @GetMapping(value = "/noise/test")
    public String test() {
        return "hello world";
    }

    @GetMapping(value = "/noise/add")
    public int getAll() throws Exception {

        double[] gps = {29, 16, 54.7981, 117, 8, 53.6982, 244.118};

        int t = 0;
        for (FlyRow flyRow : ControlUtil.readFlyFile1("E:\\upload\\flyinfo.xls")) {
            t++;
            if (t == 100)
                break;
            //1、拿到begin
            double begin = Interpolation.getBegin(flyRow, 54110, new GPS(gps));
            //2、拿到检测频率
            double freq = 30; //留好接口
            double T = 1 / freq;
            noiseDao.addFlyStatus(flyRow, begin, begin + T);

        }
        return 1;
    }

    @GetMapping(value = "/noise/sync")
    public Map<NoiseRow, FlyRow> sync() throws Exception{
        double[] ground_gps = {29, 0, 0, 117, 0, 0, 240};
        double ori = 54350;
        double freq = 30;
        Map<NoiseRow, FlyRow> res = ControlUtil.sync(ground_gps, ori, freq);

        return res;
    }




    @GetMapping(value = "/noise/arc")
    public Map<String, ArrayList<Point>> arc()
    {
        return SphereAlg.arc();
    }


    @GetMapping(value = "/noise/size")
    public int getSize() throws Exception{

        return noise_fly.size();
    }
    @GetMapping(value = "/noise/avgSize")
    public int getAvgSize() throws Exception{
        return Merge.avg(10).size();
    }
}
